#{include file="../Common/Header.html"}
<div class="layui-container fly-marginTop fly-user-main">
    #{include file="../Common/Nav.html"}
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief">
            <div class="content-header">
                <i class="layui-icon">&#xe638;</i> 我的用户
            </div>

            <div class="content-body">
                <table id="member-table"></table>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        layui.use(['hex', 'form'], function () {
            let table = $("#member");
            let cao = layui.hex;
            let queryParams = null;
            table.bootstrapTable({
                url: '/user/api/agentMember/data',//请求的url地址
                method: "post",//请求方式
                pageSize: 8,//每页显示的数量
                showRefresh: false,//是否显示刷新按钮
                cache: false,//是否使用缓存
                showToggle: false,//是否显示详细视图和列表视图的切换按钮
                cardView: false,
                pagination: true,//是否显示分页
                pageNumber: 1,//初始化显示第几页，默认第1页
                singleSelect: false,//复选框只能选择一条记录
                sidePagination: 'server',//分页显示方式，可以选择客户端和服务端（server|client）
                contentType: "application/x-www-form-urlencoded",//使用post请求时必须加上
                dataType: "json",//接收的数据类型
                queryParamsType: 'limit',//参数格式，发送标准的Restful类型的请求
                queryParams: function (params) {
                    params.page = (params.offset / params.limit) + 1;
                    if (queryParams) {
                        for (const key in params) {
                            queryParams[key] = params[key];
                        }
                    } else {
                        queryParams = params;
                    }
                    return queryParams;
                },
                //回调函数
                responseHandler: function (res) {
                    return {
                        "total": res.count,
                        "rows": res.data
                    }
                },
                columns: [
                    {field: 'id', title: 'ID', width: 80}
                    , {
                        field: 'avatar', title: '用户', formatter: function (val, item) {
                            if (!item.avatar) {
                                item.avatar = "/favicon.ico";
                            }
                            return '<span><img src="' + item.avatar + '"  style="width: 18px;border-radius: 100%;"/> ' + item.username + '</span> '
                        }
                    }
                    , {
                        field: 'group', title: '会员等级', formatter: function (val, item) {
                            return '<img style="height: 32px;" src="' + item.group.icon + '" title="' + item.group.name + ' (减免:' + (item.group.discount * 100) + '%)">'
                        }
                    }
                    , {
                        field: 'email', title: '邮箱', formatter: function (val, item) {
                            if (!item.email) {
                                return "-";
                            }
                            return item.email;
                        }
                    }
                    , {
                        field: 'phone', title: '手机号', formatter: function (val, item) {
                            if (!item.phone) {
                                return "-";
                            }
                            return item.phone;
                        }
                    }
                    , {
                        field: 'qq', title: 'QQ', formatter: function (val, item) {
                            if (!item.qq) {
                                return "-";
                            }
                            return item.qq;
                        }
                    }
                    , {
                        field: 'balance', title: '余额', formatter: function (val, item) {
                            return '<span class="acg-badge acg-badge-light-success">￥' + item.balance + '</span>'
                        }
                    }
                    , {
                        field: 'recharge', title: '总充值', formatter: function (val, item) {
                            return '<span class="acg-badge acg-badge-light-primary">' + item.recharge + '</span>'
                        }
                    }
                    , {
                        field: 'create_time', title: '注册时间'
                    }
                ]
            });

            cao.query('.search-query', table, [
                {
                    title: "查询会员ID", name: "equal-id", type: "input"
                }
            ], true, false);
        });
    });
</script>

#{ready("/assets/user/controller/user/child.js")}
#{include file="../Common/Footer.html"}
